<template>
	<view class="content">
    <view class="loginBoxFor">
      <view class="wordForText">
        登录到智慧养殖~
      </view>
      <view class="user">
       <u--input
        v-model="userName"
        placeholder="请输入账号"
        clearable
        ></u--input>
      </view>
      <view class="password">
       <u--input
         type="password"
         v-model="passWord"
         clearable
         placeholder="请输入密码"
        ></u--input>
      </view>
      <view class="confim">
        <view>
          <u-button type="primary" text="登录" @click="confirm"></u-button>
        </view>
        <!-- <view>
          <u-button type="success" text="注册" @click="testApi"></u-button>
        </view> -->
      </view>
    </view>
	</view>
</template>

<script>
  import request from './../../request/api';
	export default {
		data() {
			return {
        userName: '',
        passWord: ''
			}
		},
		onLoad() {
		},
		methods: {
      testApi(){
        const obj = {
          url: '/notify/hpDevice',
          method: 'POST',
          data: {
            time:1724139752922,
            device:390021799,
            longitude:104.103088,
            latitude:30.640527,
            temperature:26.3,
            humidity:47.5,
            quantity:96,
            signal:80
          }
        }
        request(obj).then(res => {
          // console.log(res);
        })
      },
      confirm(){
        const obj = {
          url: '/user/userLogin',
          method: 'POST',
          data: {
            userName: this.userName,
            passWord: this.passWord
          }
        }
        request(obj).then(res => {
          if (res.code === '200') {
            uni.setStorageSync('userToken', res.data.token);
            uni.setStorageSync('userMessage',JSON.stringify(res.data.sysUser))
            uni.switchTab({
              url:'/pages/home/home'
            })
          } else {
            uni.showToast({
              title: res.message,
              mask: true
            })
          }
        })
      },
      boxCenterFun(){
      }
		}
	}
</script>

<style lang="scss" scoped>
  .wordForText {
   width: 100%;
   text-align: center; 
   margin: 20rpx 0;
   font-weight: 600;
   font-size: 40rpx;
  }
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}
  .loginBoxFor {
    width: auto;
    min-width: 80%;
    height: auto;
    padding: 20rpx 50rpx;
    margin-top: 30vh;
    border: 1rpx solid #000;
  }
  .user, .password {
    width: 100%;
    margin: 30rpx 0;
  }
  .confim {
    display: flex;
    justify-content: space-around;
  }
  .confim view {
    width: 30%;
  }
</style>
